using MigraDoc.DocumentObjectModel;
using HelloMigraDoc;
using MigraDoc.Rendering;
using PdfSharp.Drawing;
using PdfSharp.Pdf;

namespace DocumentViewer
{
    sealed class SampleDocuments
    {
        static PdfDocument CreatePdfDoc()
        {
            var document = new PdfDocument();
            document.Info.Title = "Mixing MigraDoc and PDFsharp Sample";
            document.Info.Author = "Stefan Lange";
            document.Info.Subject = "Created with code snippets that show the use of MigraDoc with PDFsharp";
            document.Info.Keywords = "PDFsharp, MigraDoc";
            return document;
        }
        /// <summary>
        /// Creates the initial sample document.
        /// </summary>
        public static Document CreateSample1()
        {
            // Create a new MigraDoc document
            var document = new Document();

            // Add a section to the document
            var section = document.AddSection();
           

            // Add a paragraph to the section
            var paragraph = section.AddParagraph();

            // Add some text to the paragraph
            paragraph.AddFormattedText("Hi!");

            paragraph = section.AddParagraph();
            paragraph.AddText("This is a MigraDoc document created for the DocumentViewer sample application.");
            paragraph.AddText("The DocumentViewer demonstrates all techniques you need to preview and print a MigraDoc document, and convert it to a PDF, RTF, or image file.");

            section.AddParagraph();
            section.AddParagraph();
            paragraph = section.AddParagraph("A4 portrait");
            paragraph.Format.Font.Size = "1.5cm";

            DocumentRenderer documentRenderer = new DocumentRenderer(document);
            documentRenderer.PrepareDocument();
            var pdfDoc = CreatePdfDoc();
            var page = pdfDoc.AddPage();
            // Get Graphics obj
            XGraphics gfx = XGraphics.FromPdfPage(page);
            gfx.MUH = PdfFontEncoding.Unicode;
            gfx.DrawEllipse(new XPen(XColor.FromKnownColor(XKnownColor.Red), 2), new System.Drawing.Rectangle(100, 100, 50, 50));
            gfx.DrawLine(new XPen(XColor.FromKnownColor(XKnownColor.Red),10),new System.Drawing.Point(0,0),new System.Drawing.Point(1000,1000));
            documentRenderer.RenderPage(gfx, 1);

            section.AddPageBreak();
            section.AddParagraph().AddText("Page 2");

            section = document.AddSection();
            section.PageSetup.Orientation = Orientation.Landscape;

            paragraph = section.AddParagraph("A4 landscape");
            paragraph.Format.Font.Size = "1.5cm";

            section.AddPageBreak();
            section.AddParagraph().AddText("Page 4");

            section = document.AddSection();
            section.PageSetup.Orientation = Orientation.Portrait;
            section.PageSetup.PageFormat = PageFormat.A5;

            paragraph = section.AddParagraph("A5 portrait");
            paragraph.Format.Font.Size = "1.5cm";

            section.AddPageBreak();
            section.AddParagraph().AddText("Page 6");

            return document;
        }

        /// <summary>
        /// Creates the document from sample HelloMigraDoc.
        /// </summary>
        public static Document CreateSample2()
        {
            return Documents.CreateDocument();
        }
    }
}
